﻿using poco;
using Microsoft.VisualStudio.TestTools.UnitTesting;
using System.Collections.Generic;
namespace poco.Tests
{
    
    
    /// <summary>
    ///This is a test class for ContactJsonSerializerTest and is intended
    ///to contain all ContactJsonSerializerTest Unit Tests
    ///</summary>
    [TestClass()]
    public class ContactJsonSerializerTest
    {


        private TestContext testContextInstance;

        /// <summary>
        ///Gets or sets the test context which provides
        ///information about and functionality for the current test run.
        ///</summary>
        public TestContext TestContext
        {
            get
            {
                return testContextInstance;
            }
            set
            {
                testContextInstance = value;
            }
        }

        #region Additional test attributes
        // 
        //You can use the following additional attributes as you write your tests:
        //
        //Use ClassInitialize to run code before running the first test in the class
        //[ClassInitialize()]
        //public static void MyClassInitialize(TestContext testContext)
        //{
        //}
        //
        //Use ClassCleanup to run code after all tests in a class have run
        //[ClassCleanup()]
        //public static void MyClassCleanup()
        //{
        //}
        //
        //Use TestInitialize to run code before running each test
        //[TestInitialize()]
        //public void MyTestInitialize()
        //{
        //}
        //
        //Use TestCleanup to run code after each test has run
        //[TestCleanup()]
        //public void MyTestCleanup()
        //{
        //}
        //
        #endregion


        /// <summary>
        ///A test for Serialize
        ///</summary>
        [TestMethod()]
        public void SerializeTest_Minimum()
        {
            Contact bill = new Contact()
            {
                ID = "abc123",
                DisplayName = "Bill"
            };

            string expected = "{\"id\":\"abc123\",\"displayName\":\"Bill\"}";

            ContactJsonSerializer target = new ContactJsonSerializer();

            string actual = target.Serialize(bill);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Deserialize
        ///</summary>
        [TestMethod()]
        public void DeserializeTest_Minimum()
        {
            ContactJsonSerializer target = new ContactJsonSerializer();
            string body = "{\n\"id\":\"abc123\"\n,\"displayName\":\"Bill\"\n}\n";
            Contact expected = new Contact() { ID = "abc123", DisplayName = "Bill" }; 
            Contact actual = target.Deserialize(body);
            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Serialize
        ///</summary>
        [TestMethod()]
        public void SerializeTest_SingleComplexElement()
        {
            Contact bill = new Contact()
            {
                ID = "abc123",
                DisplayName = "Bill",
                Name = new Name() { GivenName = "William", FamilyName = "Taylor"}
            };

            string expected = "{\"id\":\"abc123\",\"displayName\":\"Bill\",\"name\":{\"familyName\":\"Taylor\",\"givenName\":\"William\"}}";

            ContactJsonSerializer target = new ContactJsonSerializer();

            string actual = target.Serialize(bill);

            Assert.AreEqual(expected, actual);
        }

        /// <summary>
        ///A test for Deserialize
        ///</summary>
        [TestMethod()]
        public void DeserializeTest_SingleComplexElement()
        {
            ContactJsonSerializer target = new ContactJsonSerializer();
            string body = "{\"id\":\"abc123\",\"displayName\":\"Bill\",\"name\":{\"familyName\":\"Taylor\",\"givenName\":\"William\"}}";
            Contact expected = new Contact()
            {
                ID = "abc123",
                DisplayName = "Bill",
                Name = new Name() { GivenName = "William", FamilyName = "Taylor" }
            };
            Contact actual = target.Deserialize(body);
            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void SerializeTest_CanonicalFieldEnum()
        {
            Contact bill = new Contact()
            {
                ID = "abc123",
                DisplayName = "Bill",
                Name = new Name() { GivenName = "William", FamilyName = "Taylor" },
                Email = new Emails(new Email[] {new Email(){ Value = "bill@company.com", Type = Email.EmailType.work}})
            };

            string expected = "{\"id\":\"abc123\",\"displayName\":\"Bill\",\"name\":{\"familyName\":\"Taylor\",\"givenName\":\"William\"},\"email\":[{\"type\":\"work\",\"value\":\"bill@company.com\"}]}";

            ContactJsonSerializer target = new ContactJsonSerializer();

            string actual = target.Serialize(bill);

            Assert.AreEqual(expected, actual);
        }

        [TestMethod]
        public void DeserializeTest_CanonicalFieldEnum()
        {
            Contact expected = new Contact()
            {
                ID = "abc123",
                DisplayName = "Bill",
                Name = new Name() { GivenName = "William", FamilyName = "Taylor" },
                Email = new Emails(new Email[] { new Email() { Value = "bill@company.com", Type = Email.EmailType.work } })
            };

            string bill = "{\"id\":\"abc123\",\"displayName\":\"Bill\",\"name\":{\"familyName\":\"Taylor\",\"givenName\":\"William\"},\"email\":[{\"value\":\"bill@company.com\",\"type\":\"work\"}]}";

            ContactJsonSerializer target = new ContactJsonSerializer();

            Contact actual = target.Deserialize(bill);

            Assert.AreEqual(expected, actual);
        }
    }
}
